<?php
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2019/12/28 0028
// +----------------------------------------------------------------------
// | Description:  
// +----------------------------------------------------------------------

namespace app\admin\controller;


use QL\QueryList;

class Querylists extends AdminBase
{

    protected  $qlist;
    public function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub

    }


    /**
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @date: 2019/12/28 0028
     * @name: index
     * @describe： 采集信息
     */
    public function index(){
        header('Content-Type: text/html; charset=utf-8');

        /*
         * $t = mb_convert_encoding($t,'ISO-8859-1','utf-8');
           $t = mb_convert_encoding($t,'utf-8','GBK');
         */

        // 切片选择器
      // $rang=".content>div";
        // 待采集的页面地址
        $url = 'https://www.cnbeta.com/';

        // 采集规则
        $rules = [
            // 文章标题
            'title' => ['dl>dt>a','text'],
            // 文章链接地址
            'link' => ['dl>dt>a','href'],
            // 文章缩略图
            'img' => ['dl>a>img','src'],
            // 文章简介
            'summary' => ['dl>dd>p','text'],
            //分类
            'type' =>['.meta-data>label>a','text'],

            'type_url' =>['.meta-data>label>a','href'],

            'desc' =>['.meta-data>ul>li','text','-li',function($d){
                 if (!empty($d)){
                     $d=explode("&nbsp;&nbsp;",$d);
                 }
                 return $d;
            }],
        ];
        // 切片选择器
        $range = '.items-area>.item';

        $data = QueryList::get($url)->rules($rules)->query()->range($range)->getData();

       // $data=QueryList::get($url)->rules($rule)->encoding('UTF-8','GB2312')->query()->range($rang)->getData();

        dump($data->all());

    }




    /**
     * @param $str
     * @return bool
     * @author: LuckyHhy <jackhhy520@qq.com>
     * @date: 2019/12/28 0028
     * @name: is_han
     * @describe：判断是否是汉字
     */
    private function is_han($str)
    {
        if (preg_match("/([\x81-\xfe][\x40-\xfe])/", $str, $match)) {
            return true;
        } else {
            return false;
        }
    }




}